#include "../include/wrapsock.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>

#define TIMEOUT     20

ssize_t 
recv_timeout(int sockfd, void *buf, size_t len)
{
    ssize_t recv_len;
    int i = 0;
    while (i++ < TIMEOUT)
    {
        if ((recv_len = recv(sockfd, buf, len, MSG_DONTWAIT)) >= 0)
        {
            return (recv_len);
        }
        sleep(1);
    }
    return (-1);
}
